<style>
.{{$t|escape:'html'}}_main {
  border-left: 15px solid #eaf2f5;
  border-right: 15px solid #eaf2f5;
  width: 1200px;
}
.{{$t|escape:'html'}}_subtitle {
  background-color: #e5f1f5;
  padding: 7px 0 7px 10px;
  font-family: Arial Black;
}
.{{$t|escape:'html'}}_emphasis {
  background-color: #d6e3e8;
  font-weight: bold;
  font-family: Trebuchet MS;
}
table.{{$t|escape:'html'}}_table {
  width: 100%;
}
table.{{$t|escape:'html'}}_table td.title {
  font-weight: bold;
  text-align: right;
  padding: 2px 10px 2px 20px;
  margin-right: 20px;
  background-color: #d6e3e8;
  font-family: Trebuchet MS;
  width: 150px;
  height: 30px;
}
table.{{$t|escape:'html'}}_table td.content {
  width: 400px;
}
.{{$t|escape:'html'}}_select {
  width: 280px;
  height: 23px;
  margin-left: 4px; 
}

.{{$t|escape:'html'}}_text {
  width: 275px;
  height: 20px;
  margin-left: 4px;
}
.{{$t|escape:'html'}}_textarea {
  width: 275px;
  height: 80px;
  margin-left: 4px;
}
.{{$t|escape:'html'}}_button {
  margin-top: 10px; 
  margin-left: 3px; 
}
table.{{$t|escape:'html'}}_list {
  width: 100%;
  border-left: 1px solid #dddddd;
  border-top: 1px solid #dddddd;
  margin-bottom: 1px;
}
table.{{$t|escape:'html'}}_list th {
  text-align: left;
  height: 30px;
  background-color: #d6e3e8;
  padding: 5px 0 5px 10px; 
  border-right: 1px solid #ffffff;
  border-bottom: 1px solid #ffffff;
  font-size: 12px;
}
table.{{$t|escape:'html'}}_list tr.drop td {
  padding-left: 0;
  border-right: 0;
  border-bottom: 0;
}
table.{{$t|escape:'html'}}_list tr.hi td {
  padding-left: 10px;
  height: 35px;
  background-color: #ff8000;
  border-right: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
}
table.{{$t|escape:'html'}}_list tr.rowodd td {
  padding-left: 10px;
  height: 35px;
  background-color: #eeeeee;
  border-right: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
}
table.{{$t|escape:'html'}}_list tr.roweven td {
  padding-left: 10px;
  height: 35px;
  border-right: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
}
table.{{$t|escape:'html'}}_list tr.rowodd:hover td {
  background-color: #f4f3b2;
}
table.{{$t|escape:'html'}}_list tr.roweven:hover td {
  background-color: #f4f3b2;
}
.{{$t|escape:'html'}}_eg {
  font-family: Trebuchet MS;
}
.{{$t|escape:'html'}}_scroll {
  overflow: auto;
  background-color: #ffffff;
}
.{{$t|escape:'html'}}_tip {
  padding-left: 10px;
  height: 35px;
  border-right: 1px solid #dddddd;
  border-left: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
  vertical-align: middle;
  line-height: 35px;
}
.{{$t|escape:'html'}}_tip:hover {
  background-color: #f4f3b2;
}
.{{$t|escape:'html'}}_select_day {
  width: 80px;
  height: 25px;
  margin-left: 4px;
}
.{{$t|escape:'html'}}_select_month {
  width: 80px;
  height: 25px;
  margin-left: 4px;
}
.{{$t|escape:'html'}}_select_year {
  width: 110px;
  height: 25px;
  margin-left: 4px;
}
</style>

<div class="{{$t|escape:'html'}}_main">
  <div>
    <div class="{{$t|escape:'html'}}_subtitle" style="text-align: center;background-color: #eaf2f5;">
      <span class="image_button" style="width: 100px;" onclick="save();">
        <table>
          <tr>
            <td><img src="image/btn/save24.png"></img></td>
            <td>{{t escape='html'}}Save{{/t}}</td>
          </tr>
        </table>
      </span>
      <span class="image_button" style="width: 100px;" onclick="history.back();">
        <table>
          <tr>
            <td><img src="image/btn/cancel24.png"></img></td>
            <td>{{t escape='html'}}Cancel{{/t}}</td>
          </tr>
        </table>
      </span>
    </div>
  <div>
  <div>
    <div class="{{$t|escape:'html'}}_subtitle">{{t escape='html'}}Basic Information{{/t}}</div>
    <table class="{{$t|escape:'html'}}_table">
      <tr>
        <td class="title">{{t escape='html'}}Track No.{{/t}}</td>
        <td class="content"><input id="{{$t|escape:'html'}}_track_no" type="text" class="{{$t|escape:'html'}}_text" style="width: 275px;"></input></td>
        
        <!--<td class="title">{{t escape='html'}}Weight (kg){{/t}}</td>
        <td class="content"><input id="{{$t|escape:'html'}}_weight" type="text" class="{{$t|escape:'html'}}_text" style="width: 275px;"></input></td>
        -->
        <td class="title">{{t escape='html'}}Delivery Date{{/t}}</td>
        <td>
          <table cellpadding=0 cellspacing=0>
            <tr>
              <td>
                <select id="{{$t|escape:'html'}}_delivery_day" class="{{$t|escape:'html'}}_select_day"><option>{{t escape='html'}} - {{/t}}</option></select>
              </td>
              <td>
                <select id="{{$t|escape:'html'}}_delivery_month" class="{{$t|escape:'html'}}_select_month"><option>{{t escape='html'}} - {{/t}}</option></select>
              </td>
              <td>
                <select id="{{$t|escape:'html'}}_delivery_year" class="{{$t|escape:'html'}}_select_year"><option>{{t escape='html'}} - {{/t}}</option></select>
              </td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td class="title">{{t escape='html'}}Comment{{/t}}</td>
        <td class="content"><textarea id="{{$t|escape:'html'}}_comment" type="text" class="{{$t|escape:'html'}}_textarea" style="width: 275px;"></textarea></td>
        <td></td>
        <td></td>
      </tr>
    </table>
  </div>
  <div>
    <div class="{{$t|escape:'html'}}_subtitle">{{t escape='html'}}Shipping Order{{/t}}<span class="{{$t|escape:'html'}}_eg"> {{t escape='html'}}(One Parcel Per Order Applied){{/t}}</span></div>
    <table class="{{$t|escape:'html'}}_table">
      <tr>
        <td class="title">{{t escape='html'}}Order No.{{/t}}</td>
        <td class="content" colSpan="3" style="width: 900px;"><input id="{{$t|escape:'html'}}_order_no" onchange="findOrder();" onkeyup="showTips();" type="text" class="{{$t|escape:'html'}}_text" style="width: 275px;" value="{{if isset($payment)}}{{$payment->name|escape:'html'}}{{/if}}"></input><span class="{{$t|escape:'html'}}_eg"> {{t escape='html'}}(e.g. 20110822120430){{/t}}</span></td>
      </tr>
      <tr>
        <td class="title">{{t escape='html'}}Goods{{/t}}</td>
        <td class="content" colSpan="3" style="width: 900px;">
          <table id="{{$t|escape:'html'}}_purchases" class="{{$t|escape:'html'}}_list" style="width: 100%;">
            <tr>
              <th>{{t escape='html'}}Good Name{{/t}}</th>
              <th style="width: 150px;">{{t escape='html'}}Price{{/t}}</th>
              <th style="width: 150px;">{{t escape='html'}}Quantity{{/t}}</th>
              <th style="width: 150px;">{{t escape='html'}}Total{{/t}}</th>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    
  </div>
  <div>
    <div class="{{$t|escape:'html'}}_subtitle">{{t escape='html'}}Shipping Method{{/t}}</div>
    <table class="{{$t|escape:'html'}}_table">
      <tr>
        <td class="title">{{t escape='html'}}Name{{/t}}</td>
        <td class="content"><select id="{{$t|escape:'html'}}_ship" class="{{$t|escape:'html'}}_select"></input></td>
        <td></td>
        <td></td>
      </tr>
    </table>
  </div>
  <div>
    <div class="{{$t|escape:'html'}}_subtitle">{{t escape='html'}}Address{{/t}}</div>
    <table class="{{$t|escape:'html'}}_table">
      <tr class="roweven">
        <td class="title">{{t escape='html'}}Name{{/t}}</td>
        <td class="content"><input id="{{$t|escape:'html'}}_addr_name" type="text" class="{{$t|escape:'html'}}_text" ></input></td>
        <td class="title">{{t escape='html'}}Address{{/t}}</td>
        <td class="content"><input id="{{$t|escape:'html'}}_addr_address" type="text" class="{{$t|escape:'html'}}_text" ></input></td>
      </tr>
      <tr class="roweven">
        <td class="title">{{t escape='html'}}Phone{{/t}}</td>
        <td class="content"><input id="{{$t|escape:'html'}}_addr_tel" type="text" class="{{$t|escape:'html'}}_text" ></input></td>
        <td class="title">{{t escape='html'}}Suburb{{/t}}</td>
        <td class="content"><input id="{{$t|escape:'html'}}_addr_suburb" type="text" class="{{$t|escape:'html'}}_text" ></input></td>
      </tr>
      <tr class="roweven">
        <td class="title">{{t escape='html'}}Mobile{{/t}}</td>
        <td class="content"><input id="{{$t|escape:'html'}}_addr_mob" type="text" class="{{$t|escape:'html'}}_text" ></input></td>
        <td class="title">{{t escape='html'}}City{{/t}}</td>
        <td class="content"><input id="{{$t|escape:'html'}}_addr_city" type="text" class="{{$t|escape:'html'}}_text" ></input></td>
      </tr>
      <tr class="roweven">
        <td class="title">{{t escape='html'}}Zip Code{{/t}}</td>
        <td class="content"><input id="{{$t|escape:'html'}}_addr_zip" type="text" class="{{$t|escape:'html'}}_text" ></input></td>
        <td class="title">{{t escape='html'}}State{{/t}}</td>
        <td class="content"><input id="{{$t|escape:'html'}}_addr_state" type="text" class="{{$t|escape:'html'}}_text" ></input></td>
      </tr>
      <tr class="roweven">
        <td class="title"></td>
        <td class="content"></td>
        <td class="title">{{t escape='html'}}Country{{/t}}</td>
        <td class="content"><input id="{{$t|escape:'html'}}_addr_country" type="text" class="{{$t|escape:'html'}}_text" ></input></td>
      </tr>
    </table>
  </div>
  <div>
    <div>
      <div class="{{$t|escape:'html'}}_subtitle" style="text-align: center;background-color: #eaf2f5;">
        <span class="image_button" style="width: 100px;" onclick="save();">
          <table>
            <tr>
              <td><img src="image/btn/save24.png"></img></td>
              <td>{{t escape='html'}}Save{{/t}}</td>
            </tr>
          </table>
        </span>
        <span class="image_button" style="width: 100px;" onclick="history.back();">
          <table>
            <tr>
              <td><img src="image/btn/cancel24.png"></img></td>
              <td>{{t escape='html'}}Cancel{{/t}}</td>
            </tr>
          </table>
        </span>
      </div>
    <div>
  </div>
</div>

<script src="jsrequest.php?script={{$t|escape:'html'}}" type="text/javascript"></script>
<script type="text/javascript">
  <!--
    if (document.addEventListener) {
      document.addEventListener('DOMContentLoaded', init, false);
    }
    window.onload = init;
    var delivery_day = document.getElementById('{{$t|escape:html}}_delivery_day');
    var delivery_month = document.getElementById('{{$t|escape:html}}_delivery_month');
    var delivery_year = document.getElementById('{{$t|escape:html}}_delivery_year');
    
    var _parcels = {{if isset($parcels)}}JSON.parse('{{$parcels|@json_encode|escape:'javascript'}}'){{else}}[]{{/if}};
    var _orders = JSON.parse('{{$orders|@json_encode|escape:'javascript'}}');
    var _purchases = JSON.parse('{{$purchases|@json_encode|escape:'javascript'}}');
    var _shippings = JSON.parse('{{$shippings|@json_encode|escape:'javascript'}}');
    var _p = null;
    var _mark = 0;
    var _days = [];
    var _months = [];
    var _years = [];
    
    for (var i = 1, il = 31; i <= il; i++) {
      _days[_days.length] = (i < 10) ? '0' + i : i;
    }
    for (var j = 1, jl = 12; j <= jl; j++) {
      _months[_months.length] = (j < 10) ? '0' + j : j;
    }
    for (var k = 2011, kl = 2055; k <= kl; k++) {
      _years[_years.length] = k;
    }
    
    function init() {
      if (!document.getElementById || !document.createElement || !arguments || arguments.callee._loaded) {
        return;
      }
      arguments.callee._loaded = true;
      
      if (_orders.length > 0) {
        document.getElementById('{{$t|escape:'html'}}_order_no').value = _orders[0].order_no;
      }
      
      if (_parcels.length > 0) {
        document.getElementById('{{$t|escape:'html'}}_track_no').value = _parcels[0].track_no;
//        document.getElementById('{{$t|escape:'html'}}_weight').value = _parcels[0].weight;
        document.getElementById('{{$t|escape:'html'}}_comment').value = _parcels[0].comment;
      }
      
      setShippings();
      setOrder();
      setDate();
    }
    
    function setDate() {
      var op1, op2, op3;
      for (var idx1 in _days) {
        var obj = _days[idx1];
        
        op1 = new Option(obj);
        op1._obj = obj;
        if (_parcels.length > 0) {
          if (op1.text == _parcels[0].date_delivery.substr(8, 2)) {
            op1.selected = 'selected';
          }
        }
        delivery_day.options[delivery_day.options.length] = op1;
      }
      for (var idx2 in _months) {
        var obj = _months[idx2];
        
        op2 = new Option(obj);
        op2._obj = obj;
        if (_parcels.length > 0) {
          if (op2.text == _parcels[0].date_delivery.substr(5, 2)) {
            op2.selected = 'selected';
          }
        }
        delivery_month.options[delivery_month.options.length] = op2;
      }
      for (var idx3 in _years) {
        var obj = _years[idx3];
        
        op3 = new Option(obj);
        op3._obj = obj;
        if (_parcels.length > 0) {
          if (op3.text == _parcels[0].date_delivery.substr(0, 4)) {
            op3.selected = 'selected';
          }
        }
        delivery_year.options[delivery_year.options.length] = op3;
      }
    }
    
    function save() {
      var err = '';
      var _day, _month, _year;
      _day = (delivery_day.options[delivery_day.selectedIndex]._obj) ? delivery_day.options[delivery_day.selectedIndex]._obj : '-';
      _month = (delivery_month.options[delivery_month.selectedIndex]._obj) ? delivery_month.options[delivery_month.selectedIndex]._obj : '-';
      _year = (delivery_year.options[delivery_year.selectedIndex]._obj) ? delivery_year.options[delivery_year.selectedIndex]._obj : '-';
      
      if (_orders.length == 0) {
        err += '{{t escape='javascript'}}Must Enter a Valid Order No.{{/t}}' + '\n\n';
      }
      if (_day == '-') {
        err += '{{t escape='javascript'}}Must Select One Day.{{/t}}' + '\n\n';
      }
      if (_month == '-') {
        err += '{{t escape='javascript'}}Must Select One Month.{{/t}}' + '\n\n';
      }
      if (_year == '-') {
        err += '{{t escape='javascript'}}Must Select One Year.{{/t}}' + '\n\n';
      }
      
      if (err != '') {
        window.alert(err);
        return;
      }
      
      var select, parcel, tmp;
      
      parcel = _parcels[0];
      if (!parcel) {
        parcel = pz_ecom_parcel.instance();
      }
      parcel.track_no = document.getElementById('{{$t|escape:'javascript'}}_track_no').value;
      //parcel.weight = document.getElementById('{{$t|escape:'javascript'}}_weight').value;
      //parcel.weight = (parcel.weight == '') ? 0 : parcel.weight;
      parcel.comment = document.getElementById('{{$t|escape:'javascript'}}_comment').value;
      
      parcel.d_day = _day;
      parcel.d_month = _month;
      parcel.d_year = _year;
      
      select = document.getElementById('{{$t|escape:'javascript'}}_ship');
      tmp = select.options[select.selectedIndex]._obj;
      parcel.ship_id = tmp.id;
      parcel.ship_name = tmp.name;
      
      parcel.addr_name = document.getElementById('{{$t|escape:'javascript'}}_addr_name').value;
      parcel.addr_tel = document.getElementById('{{$t|escape:'javascript'}}_addr_tel').value;
      parcel.addr_mob = document.getElementById('{{$t|escape:'javascript'}}_addr_mob').value;
      parcel.addr_zip = document.getElementById('{{$t|escape:'javascript'}}_addr_zip').value;
      parcel.addr_address = document.getElementById('{{$t|escape:'javascript'}}_addr_address').value;
      parcel.addr_suburb = document.getElementById('{{$t|escape:'javascript'}}_addr_suburb').value;
      parcel.addr_city = document.getElementById('{{$t|escape:'javascript'}}_addr_city').value;
      parcel.addr_state = document.getElementById('{{$t|escape:'javascript'}}_addr_state').value;
      parcel.addr_country = document.getElementById('{{$t|escape:'javascript'}}_addr_country').value;

      parcel._oid = _orders[0].id;
      new RequestUtils()._custom('save_parcel', JSON.stringify(parcel), function(result, params) {
        location.href = 'admin.php?path=ecommerce&t=parcels';
      }, {
        php: 'ecommerce/custom.php',
        pos : DOMUtils.findPos(this)
      });
    }
    
    function findOrder() {
      var txt = document.getElementById('{{$t|escape:'javascript'}}_order_no');
      
      new RequestUtils()._custom('find_order', txt.value, function(result, params) {
        if (result.order == undefined) {
          _orders = [];
          _purchases = [];
        } else {
          _orders = [ result.order ];
          _purchases = result.purchases;
        }
        setOrder();
      }, {
        php: 'ecommerce/custom.php',
        pos : DOMUtils.findPos(this)
      });
    }
    
    function setShippings() {
      var select, op;
      select = document.getElementById('{{$t|escape:'javascript'}}_ship');
      for (var idx in _shippings) {
        var obj = _shippings[idx];
        
        op = new Option(obj.name);
        op._obj = obj;
        select.options[select.options.length] = op;
      }
    }
    
    function setOrder() {
      var table, tr, td;
      table = document.getElementById('{{$t|escape:'javascript'}}_purchases');
      table.cellPadding = 0;
      table.cellSpacing = 0;
      DOMUtils.removeTableRows(table, 1);
      
      if (_orders.length == 0 || (_orders.length > 0 && (_orders[0].is_shipped == 1 && (_parcels.length > 0 && _parcels[0].id != _orders[0].parcel_id) || _parcels.length == 0))) {
        if (_orders.length > 0 && (_orders[0].is_shipped == 1 && ((_parcels.length > 0 && _parcels[0].id != _orders[0].parcel_id) || _parcels.length == 0))) {
          window.alert('{{t escape='javascript'}}This Order Has Been Shipped{{/t}}');
          _orders = [];
          _purchases = [];
        }
        
        if (_parcels.length > 0 && _orders.length == 0) {
          tr = table.insertRow(-1);
          tr.className = 'roweven';
          td = tr.insertCell(-1);
          td.colSpan = 4;
          td.style.color = '#ff0000';
          td.appendChild(document.createTextNode('{{t escape='javascript'}}Can Not Find The Old Order, Must Enter a New Valid Order No.{{/t}}'));
          return;
        } else if (_parcels.length == 0 && _orders.length == 0) {
          tr = table.insertRow(-1);
          tr.className = 'roweven';
          td = tr.insertCell(-1);
          td.colSpan = 4;
          td.style.color = '#ff0000';
          td.appendChild(document.createTextNode('{{t escape='javascript'}}Must Enter a Valid Order No.{{/t}}'));
          return;
        }
        
      }
      
      for (var idx in _purchases) {
        var obj = _purchases[idx];
        
        tr = table.insertRow(-1);
        tr.className = (idx % 2) ? 'rowodd' : 'roweven';
        td =  tr.insertCell(-1);
        td.appendChild(document.createTextNode(obj.name));
        td =  tr.insertCell(-1);
        td.appendChild(document.createTextNode('$' + obj.price));
        td =  tr.insertCell(-1);
        td.appendChild(document.createTextNode(obj.quantity));
        td =  tr.insertCell(-1);
        td.appendChild(document.createTextNode('$' + obj.total));
      }
      
      if (_purchases.length == 0) {
        tr = table.insertRow(-1);
        tr.className = 'roweven';
        td = tr.insertCell(-1);
        td.colSpan = 4;
        td.appendChild(document.createTextNode('{{t escape='javascript'}}No Purchases Found{{/t}}'));
      }
      
      var select, op, exist = false;
      select = document.getElementById('{{$t|escape:'javascript'}}_ship');
      if (_orders.length > 0) {
        for (var i = 0, il = select.options.length; i < il; i++) {
          var obj = select.options[i]._obj;
          if (obj && obj.id == _orders[0].ship_id) {
            select.selectedIndex = i;
            exist = true;
          }
        }
        if (!exist) {
          op = new Option(_orders[0].ship_name);
          op._obj = {
            id: _orders[0].ship_id,
            name: _orders[0].ship_name
          }
          select.options[select.options.length] = op;
          select.selectedIndex = select.options.length - 1;
        }
      }
      
      exist = false;
      if (_parcels.length > 0 && _parcels[0].ship_id != 0) {
        for (var i = 0, il = select.options.length; i < il; i++) {
          var obj = select.options[i]._obj;
          if (obj && obj.id == _parcels[0].ship_id) {
            select.selectedIndex = i;
            exist = true;
          }
        }
        if (!exist) {
          op = new Option(_parcels[0].ship_name);
          op._obj = {
            id: _parcels[0].ship_id,
            name: _parcels[0].ship_name
          }
          select.options[select.options.length] = op;
          select.selectedIndex = select.options.length - 1;
        }
      }
      
      document.getElementById('{{$t|escape:'javascript'}}_addr_name').value = _orders[0].addr_name;
      document.getElementById('{{$t|escape:'javascript'}}_addr_tel').value = _orders[0].addr_tel;
      document.getElementById('{{$t|escape:'javascript'}}_addr_mob').value = _orders[0].addr_mob;
      document.getElementById('{{$t|escape:'javascript'}}_addr_zip').value = _orders[0].addr_zip;
      document.getElementById('{{$t|escape:'javascript'}}_addr_address').value = _orders[0].addr_address;
      document.getElementById('{{$t|escape:'javascript'}}_addr_suburb').value = _orders[0].addr_suburb;
      document.getElementById('{{$t|escape:'javascript'}}_addr_city').value = _orders[0].addr_city;
      document.getElementById('{{$t|escape:'javascript'}}_addr_state').value = _orders[0].addr_state;
      document.getElementById('{{$t|escape:'javascript'}}_addr_country').value = _orders[0].addr_country;
    }
    
    function showTips() {
      _mark = MiscUtils.unique();
      setTimeout('showOrders(\'' + _mark + '\');', 250);
    }
    
    function showOrders(mark) {
      if (_mark != mark) {
        return;
      }
      
      var pos, div, table, tr, td, elm, txt;
      txt = document.getElementById('{{$t|escape:'javascript'}}_order_no');
      pos = DOMUtils.findPos(txt);
      
      div = document.createElement('div');
      div.style.backgroundColor = '#ffffff';
      div.style.borderBottom = '1px solid #dddddd';
      div.style.width = txt.offsetWidth + 'px';
      div.style.maxHeight = '200px';
      div.className = '{{$t|escape:'javascript'}}_scroll';
      table = document.createElement('table');
      tr = table.insertRow(-1);
      td = tr.insertCell(-1);
      elm = document.createElement('img');
      elm.src = 'image/loading.gif';
      td.appendChild(elm);
      td = tr.insertCell(-1);
      td.appendChild(document.createTextNode('{{t escape='javascript'}}Loading...{{/t}}'));
      div.appendChild(table);
      
      if (_p) {
        _p._close();
        _p = null;
      }
      _p = new Popup2(div, {
        pos: [ pos[0], pos[1] + txt.offsetHeight ]
      });
      
      document.body.onclick = function() {
        if (_p) {
          _p._close();
          _p = null;
        }
      };
      
      var cond_vals = {
        c: '`t`.`order_no` LIKE :v1',
        v: { v1: ('%' + txt.value + '%') }
      };
      if (txt.value.length > 0) {
//        new RequestUtils()._read('pz_ecom_order', cond_vals, null, null, null, null, function(result, params) {
        new RequestUtils()._custom('ezreadobj', JSON.stringify({tbl: 'pz_ecom_order', c: (JSON.stringify(cond_vals))}), function(result, params) {
          DOMUtils.removeChildElements(div);
          if (result.d.length > 0) {
            for (var idx in result.d) {
              var obj = result.d[idx];
              elm = document.createElement('div');
              elm.className = '{{$t|escape:'javascript'}}_tip';
              
              var span = getSpan(obj.order_no, txt.value);
              if (obj.is_shipped == 1 && ((_parcels.length > 0 && _parcels[0].id != obj.parcel_id) || _parcels.length == 0)) {
                span.appendChild(document.createTextNode('{{t escape='javascript'}} (Shipped){{/t}}'));
              }
              elm.appendChild(span);
              elm._obj = obj;
              elm.onclick = function () {
                txt.value = this._obj.order_no;
                findOrder();
              }
              div.appendChild(elm);
            }
          } else {
            elm = document.createElement('div');
            elm.className = '{{$t|escape:'javascript'}}_tip'
            elm.appendChild(document.createTextNode('{{t escape='javascript'}}No Orders Found{{/t}}'));
            div.appendChild(elm);
          }
        }, {
          php: 'custom.php'
        });
      } else {
        DOMUtils.removeTableRows(table, 0);
      }
    }
    
    function getSpan(result, search) {
      var pos = result.indexOf(search.toString());
      
      var str1, str2, str3;
      str1 = result.substr(0, pos);
      str2 = result.substr(pos, search.length);
      str3 = result.substr(pos + search.length);
      
      var span, sp1, sp2, sp3;
      sp1 = document.createElement('span');
      sp1.appendChild(document.createTextNode(str1));
      sp2 = document.createElement('span');
      sp2.style.backgroundColor = '#ff8000';
      sp2.appendChild(document.createTextNode(str2));
      sp3 = document.createElement('span');
      sp3.appendChild(document.createTextNode(str3));
      
      span = document.createElement('span');
      span.appendChild(sp1);
      span.appendChild(sp2);
      span.appendChild(sp3);
      return span;
    }
  // -->
</script>